package com.itboye.mengwu.app.ui.main;

import android.content.Intent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnScrollChangeListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.AbsListView.OnScrollListener;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.web.WebActivity;
import com.itboye.mengwu.goodsdetail.snapscrollview.McoySnapPageLayout.McoySnapPage;
import com.umeng.common.message.Log;

public class TuWenXiangQingFragment extends BaseFragment implements
		McoySnapPage {
	WebView web;
	private String urls = "http://www.moodwo.com/index.php/Webview/";
	private String pid;
	WebSettings settings;
	ProgressBar myProgressBar;
	String uid;
	String psw;
	private boolean isAtTop;
	private boolean isIdle;
	float old_x;
	float old_y;

	public TuWenXiangQingFragment(String pid) {
		// TODO Auto-generated constructor stub
		this.pid = pid;
	}

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.fragment_tuwenxiangqing;
	}

	@Override
	public void onMyActivityCreated() {
		// TODO Auto-generated method stub
		uid = (String) SPUtils.get(getActivity(), null, SpPublicParams.UID, "");
		psw = (String) SPUtils.get(getActivity(), null,
				SpPublicParams.PASSWORD, "");
		settings = web.getSettings();
		settings.setSupportZoom(true);
		settings.setJavaScriptEnabled(true);
		settings.setUseWideViewPort(true);
		settings.setLoadWithOverviewMode(true);
		web.setWebViewClient(new WebViewClient() {

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// TODO Auto-generated method stub
				return true;
			}
		});
		web.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN:
					old_x = event.getX();
					old_y = event.getY();
					break;
				case MotionEvent.ACTION_MOVE:
					System.out.println("-----move------");
					if ( Math.abs(old_y - event.getY())
									/ Math.abs(old_x - event.getX()) > 3) {
						System.out.println("-----init------");
						setParentScrollAble(false);
					}
					// setParentScrollAble(false);
					break;
				case MotionEvent.ACTION_UP:
				case MotionEvent.ACTION_CANCEL:
					setParentScrollAble(true);
					//
					break;

				}
				return false;
			}

			private void setParentScrollAble(boolean b) {
				// TODO Auto-generated method stub
				((ViewParent) getParentFragment()).requestDisallowInterceptTouchEvent(!b);
			}

		});
		web.loadUrl(urls + "product/detail?uid=" + uid + "&psw=" + psw + "&id="
				+ pid);
		Log.e("hu--tuwen", urls + "product/detail?uid=" + uid + "&psw=" + psw
				+ "&id=" + pid);
	}

	@Override
	public View getRootView() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isAtTop() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isAtBottom() {
		// TODO Auto-generated method stub
		return isAtTop;
	}

}
